import {defineStore} from "pinia";
import {computed, ref} from "vue";
import axios from "axios";

export const useCounterStore = defineStore("counter", () => {
    //定义数据
    const count = ref(0);
    const url = 'http://geek.itheima.net/v1_0/channels'
    const list = ref([])
    //定义方法
    const increment = () => {
        count.value++;
    }
    //getter实现
    const doubleValue = computed(() => {
        return count.value * 2
    });
    //异步action
    const getList = async () => {
        const res = await axios.get(url)
        list.value = res.data.data.channels
    }
    //以对象的显示返回
    return {
        count,
        increment,
        doubleValue,
        list,
        getList
    }
})